<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目到账提款管理列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
         <div class="fieldBox ">
                    <div class="label">项目名称</div>
                <div class="field">
                    <input name="fncprjnm" id="fncprjnm" type="text" class="ui-textbox" value="${fncprjnm}" >
                </div>
                <div style="display: none">
                </div>
             </div>
             <div class="fieldBox ">
                <div class="label">金融机构</div>
                <div class="field">
                    <input name="fncinsid" id="fncinsid" type="text" class="ui-textbox" value="" placeholder="请选择"  ltype="combobox">
                </div>
                <div style="display: none">
                </div>
             </div>
           <div class="fieldBox ">
                    <div class="label">预计到账日期</div>
                <div class="field"> 
                    <input name="expwddatebegin" id="expwddatebegin"  type="text"  class="ui-datepicker" value="" validate="{required:true}">~
                    <input name="expwddateend" id="expwddateend"  type="text"  class="ui-datepicker" value="" validate="{required:true}">
                </div>
                <div style="display: none">
                </div>
             </div>      
            <div class="fieldBox">
                <div class="label">到账状态</div>
                <div class="field">
                     <select name="transst" id="transst" data-value="">
                       <option value="" selected="selected">请选择</option>
                       <c:forEach items="${transstlist}" var="kv">
                     		<option value="${kv.key}">${kv.value}</option>
                       </c:forEach>
                    </select>
                </div>
            </div>    
         </div>
            <div class="clearFix"></div>
            <div class="btnsBox">
               <span id="searchBtn" onclick="searchBtn();"  class="sq-button sq-button-round">查询</span>
               <span id="clearBtn" onclick="clearBtn();" class="sq-button sq-button-round">清空</span>
              <!-- 
               <span id="flowStartBtn" class="sq-button sq-button-round" onclick="flowStart();">发起流程</span>
               -->
              
            </div>

			
        </div>
    </form>
</div>
<div id="ligergrid1" class="sq-grid"></div> 
</div>

<script type="text/javascript">
	var grid = null;
	var queryFlag ="${queryFlag}"; //只查询列表
	$(function () {
		initcombobox();
	    $("#ligergrid1").ligerGrid({
	    	url: '<%=path%>/rfbuss/fncprjbscinfo/initList.do?checkflag=1',
	    	method : 'get',	 
	    	
	        columns: [
	            { display: '到账状态', name: 'transstNM', minWidth: 140 ,enabledSort:true}, 
	            
	            { display: '融资机构', name: 'fncinsNM', minWidth: 140 , enabledSort:true}, 
	            
	            { display: '融资报价', name: 'fncscmNM', minWidth: 140 , enabledSort:true}, 
	            
	            { display: '项目编号', name: 'fncprjid', minWidth: 140 , 
                        render: function (rowdata, rowindex, value, column) { 
	            		
	            		var h = '';
	            			if(value&&value!="null"){
	            		    h+='<a href="javascript:detailBtn(';
	                        h+="'"+rowdata.id+"'";
	                        h+=')">'+value+'</a>'
	            			}
	                        return h;
	            		},
	            	enabledSort:true}, 
	          

	            { display: '项目名称', name: 'fncprjnm', minWidth: 140 , enabledSort:true}, 

	            { display: '预计到账日期', name: 'expwddate', minWidth: 140 ,enabledSort:true,render:renderDate}, 
	                { display: '首付金额', name: 'fstpyamtall', minWidth: 140 ,
		            	 render: function (rowdata, rowindex, value, column) { 
			            		
			            		var h = '';
			            			if(value&&value!="null"){
			            		    h+=fmoney(value/100.00, 2);
			            			}else{
			            				h+=0.00;
			            			}
			                        return h;
			            		},
		            	
		            	enabledSort:true},          
		        { display: '是否坐扣', name: 'wthrddct', minWidth: 140 , enabledSort:true,
		            		render: function (rowdata, rowindex, value, column) { 
		                		
		                		var h = '';
		                			if(value=="1"){
		                		         h+="是";
		                			}else if(value=="0"){
		                				 h+="否";	
		                			}else{
		                				 h+="是/否";
		                			}
		                            return h;
		                		},   		
		        }, 
		        
	            { display: '到账金额', name: 'transam', minWidth: 140 , render: function (rowdata, rowindex, value, column) { 
            		
            		var h = '';
            			if(value!=null && value!=""){
            		    h+=fmoney(value/100.00, 2);
            			}else{
            				h+=0.00;
            				
            			}
                        return h;
            		},
        	
        	enabledSort:true}, 
 
	            getOptColumn()
	        ],
	        pageSize:20,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:true,
	        rownumbers:true
	    });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();
	    
	
	
	});
	
	//获取操作列
	function getOptColumn(){
		if(queryFlag!="query"){
		var column = {
                display: '操作',
                isSort: false,
                width: 260,
                align:'left',
                render: function (rowdata, rowindex, value){
                	 var h="";
                	 if(rowdata.transst=="0"){
                		 h+='<a class="sq-button-hasicon" href="javascript:addBtn(';
                         h+="'"+rowdata.id+"'";
                         h+=')"><i class="sqBtnIco_4"></i>确认到账</a>' 
                	 }
                	 else if(rowdata.transst=="1"){
                	//	 h+='<a class="sq-button-hasicon" href="javascript:addBtn(';
                      //   h+="'"+rowdata.id+"'";
                      //   h+=')"><i class="sqBtnIco_4"></i>确认到账</a>' 
                	     h+='<a class="sq-button-hasicon" href="javascript:payplanBtn(';
                         h+="'"+rowdata.id+"'";
                         h+=')"><i class="sqBtnIco_1"></i>查看到账信息</a>'  
                    
                	 }
                	 else{
                       	 h+='<a class="sq-button-hasicon" href="javascript:payplanDetail(';
                         h+="'"+rowdata.id+"'";
                         h+=')"><i class="sqBtnIco_1"></i>查看还款表</a>'  
                	 }
                       
                	/*   h+='<a class="sq-button-hasicon" href="javascript:commShowFlow(';
                      h+="'"+rowdata.pInstId+"'";
                      h+=')"><i class="sqBtnIco_7"></i>查看流程</a>' */
                    return h;
                }
            }
		return column;
		}else{
			var column =  {};
			return column;
		}
	}
	
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	function addBtn(id){
		var callback = function(val,info){
			//alert(info);
			if(info==null) 
				info="修改成功!";
			if(val==null) val="success";
			top.$.ligerDialog.SQalert({content:info,SQ_type:val});
			 grid.reload();
		}
		  var TAB=top.mainApp.parentTab;
          var currentTabid=TAB.getSelectedTabItemID();
		Add_navTab('fnc_prj_bsc_info_trans_add'+id,'再融资项目确认到账信息','<%=path%>/rfbuss/fncprjbscinfo/toTransferAddPage.do?id='+id+'&chflag=1&currentTabid='+currentTabid,callback);
	}
	
	function searchBtn(){

        var form = new liger.get("searchBar");
        var data = form.getData();
        for (name in data){
           grid.setParm(name,data[name]);
        };
       grid.reload();
	}
	function modifyBtn(id){
		var callback = function(){
			 grid.reload();
		}
		/* var selectedRows = grid.getSelectedRows();
		if(selectedRows.length != 1){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
			return;
		} */
		var fromPrjFlag = true;
		var _flag = $("#fromPrjFlagId").val();//来自哪里
		if(StringUtils.isNotEmpty(_flag)){
			if(_flag == 'false'){
				fromPrjFlag = false;
			}
		}
		//查询参数
		var detailFlag = false;
	//	var params = "?fromPrjFlag="+fromPrjFlag+"&id="+id+"&detailFlag="+detailFlag;
	var params="?id="+id;
		//如果客户ID存在则加入参数

		//var id = selectedRows[0].id;
		Add_navTab('fnc_prj_bsc_info_trans_add'+id,'再融资项目确认到账信息','<%=path%>/rfbuss/fncprjbscinfo/toAddPage.do'+params,callback);
	}
	//录入还款表信息
	function payplanBtn(id){
		var callback = function(){
			 grid.reload();
		}
		  var TAB=top.mainApp.parentTab;
          var currentTabid=TAB.getSelectedTabItemID();
		var params="?id="+id+"&chflag=1&currentTabid="+currentTabid;

		Add_navTab('fnc_prj_bsc_pay_plan_add'+id,'再融资项目到账信息','<%=path%>/rfbuss/fncprjbscinfo/toTransferDetailPage.do'+params,callback);		
		
	}
	function payplanDetail(id){
		var callback = function(val){
			if(val==null) val="error";
		//	top.$.ligerDialog.SQalert({content: msg.info,SQ_type: val});
		}
		var params="?id="+id;

		Add_navTab('fnc_prj_bsc_pay_plan_detail'+id,'再融资项目录入还款表信息','<%=path%>/rfbuss/fncprjbscinfo/topayplanDetailPage.do'+params,callback);		
		
	}
	
	function detailBtn(id){
		Add_navTab('tab_project_detail'+id,'项目基本信息详情','<%=path%>/rfbuss/fncprjbscinfo/toDetailPage1.do?id='+id);
	}
	//启动流程
	function flowStart(){
		var selectedRows = grid.getSelectedRows();
        if (selectedRows.length != 1) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
            return;
        }
        var modelTyp = "R005";
        var flowDialog = $.ligerDialog.SQopen({
            url: '<%=path%>/flow/flow/toForStartListPage.do?modelTyp='+modelTyp,
            width: 700,
            height:400,
            title : '请选择要发起的流程',
            buttons: [{
	                text: "确定", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ],
            onClose: function () {
            	var json = flowDialog._DATA;
            	alert(json.procDefId);
            	alert(json.procDefKey);
            	alert(json.procNo);
            	console.log(json);
            	if(!json){
                	return;
            	}
            	var wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting",onClose: function () {}});
        		var _id = selectedRows[0].id;
        		
            }
        });
	}
	
	
	
	
	
 
  function clearBtn(){
    $("#searchBar").ligerForm();
			var form = new liger.get("searchBar");
			//form.clear(); 
			form.setData({
				prjNm:" ",
				cstNm:" ",
				prjTypCd:" ",
				bizTypCd:" ",
				prjStsCd:" ",
				orgCd:" ",
				"fncprjnm":"",
				"fncinsid":"",
				"expwddatebegin":"",
				"expwddateend":"",
				"transst":"",
				lsCntNo:" "
			 });
	}
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    }
	}
	
	function fmoney(s, n)   
	{   
	   n = n > 0 && n <= 20 ? n : 2;   
	   s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";   
	   var l = s.split(".")[0].split("").reverse(),   
	   r = s.split(".")[1];   
	   t = "";   
	   for(i = 0; i < l.length; i ++ )   
	   {   
	      t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");   
	   }   
	   return t.split("").reverse().join("") + "." + r;   
	} 
	var frilist = [];
	<c:if test="${not empty frilist}"> frilist = ${frilist}; </c:if>
	 function initcombobox(){
		  var combobox=  $("#fncinsid").ligerComboBox({
	    	     data:frilist,
	             selectBoxWidth: 270,
	             selectBoxHeight: 150,
	             valueField: "id",
	             textField: "fundRasInsNm",
	             autocomplete: function (e){
	                 filter_autoComboboxData(e.key, this);
	                 e.show();
	             }
	          });
	 }
</script>

</body>
</html>